package com.supreme.businessserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.supreme.businessserver.mapper.mybatis.MBQualityMapper;
import com.supreme.commonentity.mysql.primary.BizQuality;
import com.supreme.commonboot.utils.AjaxResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "quality")
public class QualityController {

    private final MBQualityMapper mbQualityMapper;

    @Autowired
    public QualityController(MBQualityMapper mbQualityMapper) {
        this.mbQualityMapper = mbQualityMapper;
    }

    @PostMapping(value = "createQuality")
    public AjaxResp createProduct(@RequestBody BizQuality quality) {
        int result = this.mbQualityMapper.insert(quality);
        return new AjaxResp(result);
    }

    @GetMapping(value = "searchQuality")
    public AjaxResp searchProduct() {
        QueryWrapper<BizQuality> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderBy(true, true, "quality_code");
        List<BizQuality> qualityList = this.mbQualityMapper.selectList(queryWrapper);
        return new AjaxResp(qualityList);
    }
}
